<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的收货地址</title>
    <meta charset="UTF-8">
    <title>我的收货地址</title>
    <meta name="keywords" content="我的收货地址"/>
    <meta name="description" content="我的收货地址"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <link th:href="@{/shoppingApi/css/weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/jquery-weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/public.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/publicOfuser.css}" rel="stylesheet">
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header"  th:content="${_csrf.headerName}"/>
    <style>
        .selectadd {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 1px solid #ddd;
            border-radius: 50%;
            vertical-align: text-bottom;
        }
        .selectadd.default {
            position: relative;
            border-color: #f7012a;
        }
        .selectadd.default:after {
            content: '';
            display: block;
            position: absolute;
            top: 2px;
            left: 2px;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #f7012a;
        }
    </style>
</head>
<body>
<div class="main">
    <div class="main_con c323232">
        <div class="weui-cells" style="background-color: #f0f0f0; margin: 0 0 50px;">
            <div class="weui-cell mt10" th:each="model:${list.address}" style="padding: 0px">
                <div class="weui-cell__bd bgfff pt15 pb15 address-list">
                    <div class="select-area"  th:data-id="${model.id}">
                        <div class="flex flex-pj ft15 pr15 pl15">
                            <span th:text="${model.name}"></span>
                            <span th:text="${model.phone}"></span>
                        </div>
                        <div class="flex flex-pj flex-wrap ft12 mt10  pr15 pl15">
                            <span th:text="${model.provinceName+model.cityName+model.areaName}"></span>
                            <span th:text="${model.detailAddr}"></span>
                        </div>
                    </div>
                    <hr class="hr1 mt10">
                    <div class="flex flex-pj ft12 mt10  pr15 pl15">
                        <div th:data-id="${model.id}">
                            <label th:if="${model.isdefault==1}" class="selectadd default"><!--<input checked="checked" type="radio" style="display:none;">--></label>
                            <label th:if="${model.isdefault==0}" class="selectadd"><!--<input type="radio" style="display:none;">--></label>
                            <span class="ml5">默认地址</span>
                        </div>
                        <div>
                            <a class="fl">
                                <div><img src="/shoppingApi/images/address_edit.png" style="width: 20px;height: 20px;">
                                    <span onclick="edit(this);" th:data="${model.id}" class="ml10">编辑</span></div>
                            </a>
                            <a class="fl">
                                <div style="margin-left: 13px;"><img src="/shoppingApi/images/address_delete.png" style="width: 20px;height: 20px;">
                                    <span onclick="deleteAddress(this);"  th:data="${model.id}"  class="ml10">删除</span></div>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="javascript:" onclick="add();" class="fixed-address">+ 添加地址</a>
</div>
<!--<a class="back-user-btn" href="/wap/openUserCenter"><span>返回个人中心</span></a>-->
<!--快速导航-->
<div class="mini-mask"></div>
<div class="mini-btn"></div>
<div class="mini-nav">
    <ul>
        <li><a href="/">
            <h5>首页</h5>
        </a></li>
        <li><a href="/wap/selectProductYJAndRjClassfy">
            <h5>分类</h5>
        </a></li>
        <li><a href="javascript:sharebtn()">
            <h5>分享</h5>
        </a></li>
        <li><a href="/wap/openUserCenter">
            <h5>个人中心</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>店铺</h5>
        </a></li>
        <li><a href="/wap/getCartList">
            <h5>购物车</h5>
        </a></li>
        <li><a href="javascript:alert('敬请期待...')">
            <h5>联系客服</h5>
        </a></li>
    </ul>
</div>
<div id="mini-popup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="miniShareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="miniShareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
<!--/快速导航-->
</body>
<script th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{/shoppingApi/js/jquery-weui.min.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/plusShare.js}"></script>
<script th:src="@{/shoppingApi/js/mininav.js}"></script>
<script type="text/javascript">
    $(function () {
        // 设置地址
        var redirection = location.href.split('=')[1] || sessionStorage.getItem('redirection') || '';
        if (redirection) {
            sessionStorage.setItem('redirection', redirection);
        }
        $('.select-area').on('click', function (e) {
            var addId = $(this).data('id');
            if (redirection) {
                $.ajax({
                    type: 'get',
                    url: '/wap/updateDefaultAddress?Id=' + addId,
                    success: function (res) {
                        console.log(res)
                        if (res.updateState == '000001') {
                            location.href = decodeURIComponent(redirection);
                            sessionStorage.removeItem('redirection');
                        }
                    }
                });
            }
        });

        $('.selectadd').on('click', function (e) {
            var addId = $(this).parent().data('id');
            var _that = $(this);
            $.ajax({
                type: 'get',
                url: '/wap/updateDefaultAddress?Id='+addId,
                success: function (res) {
                    if (res.updateState == '000001') {
                        $('.selectadd').removeClass('default');
                        _that.addClass('default');
                        if(res.updateAddressURL!=null){//修改地址不是在用户中心页面，则需要跳转到修改的起始页面
                            window.location.href=res.updateAddressURL;
                        }
                    } else {
                        $.toast('设置出错了', 'cancel');
                    }
                }
            });
        });
    });

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return encodeURIComponent(unescape(r[2]));
        return null;
    }
    function edit(obj) {
        var redirection = getQueryString("updateAddressURL");
        window.location.href='/wap/myAddressEdit?id='+$(obj).attr('data')+'&updateAddressURL='+redirection;
    }
    function add() {
        var redirection = getQueryString("updateAddressURL");
        window.location.href="/wap/myAddressAdd?updateAddressURL="+redirection;
    }
    function deleteAddress(obj) {
        $.toast.prototype.defaults.duration = 5000;
        $.ajax({
            url: '/wap/addressDelete?addressId='+$(obj).attr('data'),
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            async: false,
            success: function(data){
                if(data.data>0){
                    $.toast('删除成功！', 'text');
                    window.location.href='/wap/myAddress';
                }else {
                    $.toast('删除失败！', 'cancel');
                    // alert("删除失败!");
                }
            }
        });
    };
</script>
</html>